package com.sixdog.regulate.service.impl;

import com.sixdog.regulate.bean.CmdResult;
import com.sixdog.regulate.cmdService.CmdUtils;
import com.sixdog.regulate.service.GestureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GestureServiceImpl implements GestureService {
    @Autowired
    private CmdUtils cmdUtils;
    //单次点击
    @Override
    public CmdResult onClick(String deviceSerial, int x, int y) {
        StringBuilder command = new StringBuilder().append("adb -s ").append(deviceSerial).append(" exec-out input tap ").append(x).append(" ").append(y);
        CmdResult cmdResult = cmdUtils.execute(command);
        return cmdResult;
    }

    //自定义点击(durationMS持续时长,intervalMS间隔时长[低于50毫秒会丢失点击])(单位：毫秒)
    @Override
    public CmdResult onClickCustom(String deviceSerial, int x, int y, int durationMS, int intervalMS) {
        StringBuilder command = new StringBuilder().append("adb -s ").append(deviceSerial).append(" exec-out input tap ").append(x).append(" ").append(y);
        CmdResult cmdResult = cmdUtils.continuityExecute(command, durationMS, intervalMS);
        return cmdResult;
    }

    //滑动(StartX,StartY开始坐标;endX,endY结束坐标;durationMS持续时长)
    @Override
    public CmdResult onStroke(String deviceSerial, int StartX, int StartY, int endX, int endY, int durationMS) {
        StringBuilder command = new StringBuilder().append("adb -s ").append(deviceSerial).append(" exec-out input swipe ")
                .append(StartX).append(" ")
                .append(StartY).append(" ")
                .append(endX).append(" ")
                .append(endY).append(" ")
                .append(durationMS);
        //adb -s 3431375099001IR exec-out input swipe 700 250 50 250 100
        CmdResult cmdResult = cmdUtils.execute(command);
        return cmdResult;
    }

    //输入字符
    @Override
    public CmdResult inputString(String deviceSerial, String text) {
        StringBuilder command = new StringBuilder().append("adb -s ").append(deviceSerial).append(" exec-out input text ").append(text);
        CmdResult cmdResult = cmdUtils.execute(command);
        return cmdResult;
    }


}
